<?php

namespace App\Services;

use App\Models\Address;

class AddressService extends BaseService {

    /**
     * 根据用户Id获取地址列表
     * @param $userId
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function getListByUserId($userId)
    {
        return Address::query()->where('user_id','=',$userId)
            ->get();
    }

    public function deleteById($userId,$id)
    {
        return Address::query()->where('user_id','=',$userId)
            ->where('id','=',$id)
            ->delete();
    }

    public function getById($userId,$id)
    {
        return Address::query()->where('user_id','=',$userId)
            ->where('id','=',$id)
            ->first();
    }

    public function saveById(array $data,int $userId,int $id): int
    {
        return Address::query()->where('user_id','=',$userId)
            ->where('id','=',$id)->update($data);
    }

    public function create(array $data)
    {
        return Address::query()->create($data);
    }
}
